package com.mc.moring.netconfig

import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import com.mc.moring.base.BaseApplication
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response


class HeadtInterceptor :Interceptor{

    override fun intercept(chain: Interceptor.Chain): Response {
        val app_id = BaseApplication.getInstance().packageName
        val request: Request = chain.request()
        request.headers.newBuilder().add("App_id","com.mc.moring")
        request.headers.newBuilder().add("App_name", "MONI CASH")
        request.headers.newBuilder().add("App_version",getVersionID())
        request.headers.newBuilder().add("User-Agent","Retrofit-Sample-App")
//        request.headers.newBuilder().add("distinctId","android")
        request.headers.newBuilder().add("Authorization","")
        request.headers.newBuilder().add("accept-language","es")

        return chain.proceed(request)
    }

    private fun getVersionID(): String {
        var appVersionName = ""
        val manager = BaseApplication.getInstance().packageManager
        try {
            val info: PackageInfo = manager.getPackageInfo(BaseApplication.getInstance().packageName, 0)
            appVersionName = info.versionName
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
        }
        return appVersionName
    }
}